import { useStore, mapState } from "vuex"
import { computed } from "vue"

export function useState(mapper) {
  const store = useStore()

  const stateFns = mapState(mapper)
  /* console.log(stateFns["counter"])
    ƒ mappedState () {
    var state = this.$store.state;
    var getters = this.$store.getters; 
    if (namespace) {
      var module = getModuleByNamespace(this.$store, 'mapState', namespace);
  */

  const state = {}

  Object.keys(stateFns).forEach((fnKey) => {
    const fn = stateFns[fnKey].bind({ $store: store })
    state[fnKey] = computed(fn)
  })

  return state
}
